﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace FasterWPF
{
    public static class WrapPanelExt
    {
        public static WrapPanel SetBackgroundColor(this WrapPanel chain, Brush brush)
        {
            Brush newBrush = (brush);
            chain.Background = newBrush;
            return chain;
        }

        public static WrapPanel Initialize(this WrapPanel source, double width, double height, ContainerType containerType, double itemHeight, double itemWidth, Orientation orientation, FlowDirection flowDirection)
        {
            //Force the Aero theme by default to assure the structure of the Listbox
            Uri uri = new Uri("/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml", UriKind.Relative);
            source.Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary);

            source.ItemHeight = itemHeight;
            source.ItemWidth = itemWidth;
            source.FlowDirection = flowDirection;
            source.Orientation = orientation;
            source.Width = width;
            source.Height = height;
            
            sharedWrapPanelInitializeCode(source, containerType);
      
            return source;
        }

        public static WrapPanel Initialize(this WrapPanel source, double width, double height, ContainerType containerType, Orientation orientation, FlowDirection flowDirection)
        {   
            //Force the Aero theme by default to assure the structure of the Listbox
            Uri uri = new Uri("/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml", UriKind.Relative);
            source.Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary);

            source.FlowDirection = flowDirection;
            source.Orientation = orientation;
            source.Width = width;
            source.Height = height;

            sharedWrapPanelInitializeCode(source, containerType);

            return source;
        }

        private static void sharedWrapPanelInitializeCode(WrapPanel source, ContainerType containerType)
        {
            source.SetContainerType(containerType);
            IComposite icomp = CompositeTypeHelper.CreateIComposite<WrapPanel>(source);
            source.SetIComposite<WrapPanel>(icomp);

            //STORE SETTING BUILD CHAIN AND GET CHAIN?!?  Put these in a Composite implements an interface
            WrapPanelParent gbsr = new WrapPanelParent();
            source.StoreSetting<WrapPanel>("IParent", gbsr);

            source.AddItemBorder(Brushes.Gray, new Thickness(1, 1, 1, 1)); //default Border     
            source.StoreSetting<WrapPanel>("BorderSettings", new BorderSettings() { Width = double.NaN, Height = double.NaN, BorderBrush = Brushes.Gray, BorderThickness = new Thickness(0, 0, 0, 0), CornerRadius = new CornerRadius(0), Padding = new Thickness(0) });
        }
        
    }//end of class
}//end of namespace
